package dmas.lab.schedulers;

import java.math.BigInteger;

public abstract class Event implements Runner{

	private final TaskCaller taskCaller;
	private boolean ignored = false;
	private final BigInteger eventID;

	public Event(BigInteger eventID, TaskCaller taskCaller) {
		this.eventID = eventID;
		this.taskCaller = taskCaller;
	}

	/***
	 * Runs a specified Task
	 */
	@Override
	public void run() {
		try {
			handleResult(runTask());
		} catch (Exception e) {
			taskCaller.handleException(e);
		}
	}
	
	/**
	 * Handles data returned by Task and passes those to caller
	 * @param data
	 */
	private void handleResult(Event data){
		taskCaller.callback(data);
	}

	public TaskCaller getCallback() {
		return taskCaller;
	}

	@Override
	public abstract Event runTask() throws Exception;

	public void setIgnored(boolean ignored) {
		this.ignored = ignored;
	}

	public boolean isIgnored() {
		return ignored;
	}

	public BigInteger getEventID() {
		return eventID;
	}
}
